﻿using System;
using Enum;

namespace Struct {

    [Serializable]
    public class PropertiesStruct {

        /// <summary>
        ///     附加属性的类型
        /// </summary>
        ///<summary>附加属性的类型///</summary>
        public EnumPropertiesType propertiesType;

        /// <summary>
        ///     值
        /// </summary>
        ///<summary>值///</summary>
        public int value;

        /// <summary>
        ///     是百分比 如果为true 则value为百分比值
        /// </summary>
        ///<summary>是否百分比///</summary>
        public bool isPercentage;

        ///summary>
        /// 临时值
        /// </summary>
        [HideInInspector]
        public int tempValue;
        public PropertiesStruct() { }

        public PropertiesStruct(EnumPropertiesType propertiesType, int value, bool isPercentage) {
            this.propertiesType = propertiesType;
            this.value = value;
            this.isPercentage = isPercentage;
        }

        public PropertiesStruct(EnumPropertiesType propertiesType, int value) : this() {
            this.propertiesType = propertiesType;
            this.value = value;
        }



        public float GetPercentageValue() {
            // 10 / 100 = 0.1
            return (float)value / 100;
        }

        /// <summary>
        ///     计算属性
        /// </summary>
        /// <param name="equipPs"></param>
        public void Merge(PropertiesStruct equipPs) {
            value += equipPs.value;
        }

        /// <summary>
        ///     计算百分比的属性
        /// </summary>
        /// <param name="equipPercentPs"></param>
        public void MergePercent(PropertiesStruct equipPercentPs) {
            value += (value * equipPercentPs.value / 100f).CeilToInt();
        }

        /// <summary>
        ///     计算属性并返回变化值
        ///  int old, int new
        /// </summary>
        /// <param name="equipPercentPs"></param>
        /// <returns></returns>
        public (int,int) ComputedProperties(PropertiesStruct equipPercentPs) {
            int oldValue = this.value;
            if (equipPercentPs.isPercentage) {
                MergePercent(equipPercentPs);
            } else {
                Merge(equipPercentPs);
            }
            int newValue = this.value;
            return (oldValue, newValue);

        }
    }

}